<%--
  Created by IntelliJ IDEA.
  User: 王一同
  Date: 2021/11/20
  Time: 12:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../../component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <input type="hidden" name="id">
                <div class="layui-form-item">
                    <label class="layui-form-label">部门id</label>
                    <div class="layui-input-block">
                        <input type="text" name="departmentId" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">部门名称</label>
                    <div class="layui-input-block">
                        <input type="text"  name="departmentName" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">部门状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="dstatus" value="1" title="启用" checked>
                        <input type="radio" name="dstatus" value="0" title="停用" >
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">部门描述</label>
                    <div class="layui-input-block">
                        <input type="text"  name="departmentDisc" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script>
    layui.use(['form','jquery'],function(){
        let form = layui.form;
        let $ = layui.jquery;

        form.on('submit(user-save)', function(data){
            let roleIds = "";
            $('input[type=checkbox]:checked').each(function() {
                roleIds += $(this).val()+",";
            });
            roleIds = roleIds.substr(0,roleIds.length-1);
            data.field.roleIds = roleIds;
            $.ajax({
                url:'${pageContext.request.contextPath}/insertDepartment',
                data:data.field,
                dataType:'json',
                type:'post',
                success:function(result){
                    if(result.code==200){
                        layer.msg(result.msg,{icon:1,time:1000},function(){
                            // alert(parent)
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("#organization-table");
                            parent.layui.table.reload("organization-table");
                            // var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            // alert(index);
                            // // parent.layui.table.reload('test-table-toolbar');
                            // parent.layui.table.reload("user-table");
                            // parent.layer.close(index); //再执行关闭

                        });
                    }else{
                        layer.msg(result.msg,{icon:2,time:1000});
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>